package qt

import (
	"bytes"
	"github.com/gin-gonic/gin"
	"iot-base/auth/api/logic"
	"iot-base/auth/config"
	"iot-base/auth/types"
	"iot-base/auth/utils"
	"os/exec"
)

func OpenVideo(c *gin.Context) {

	resp := types.NewResult(c)
	videoList, err := logic.NewCameraLogic().GetVideoList()
	//fmt.Println("videoList", videoList)
	videos := make([]map[string]string, 0, len(videoList))
	if err == nil && len(videoList) > 0 {
		for _, value := range videoList {
			temp := map[string]string{
				"id":         value["thing_id"],
				"thing_name": value["thing_name"],
				"url":        value["url"],
			}
			videos = append(videos, temp)
		}
		utils.Save(gin.H{"videos": videos, "key": config.Conf.Qt.Key, "url": config.Conf.Qt.Url}, config.Conf.Qt.ConfigPath)
	}
	//函数返回一个*Cmd，用于使用给出的参数执行name指定的程序
	cmd := exec.Command("/bin/bash", "-c", config.Conf.Qt.VideoPath)
	var out bytes.Buffer
	cmd.Stdout = &out
	cmd.Run()
	resp.Success(gin.H{})
}
